package com.xq.shop.util;

import java.lang.reflect.Type;

import com.google.gson.ExclusionStrategy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSerializer;

public class GsonUtil {

	private static final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
	
	public static String toJson(Object obj){
		return gson.toJson(obj);
	}
	
	public static String toJson(Object obj, ExclusionStrategy strategy){
		return new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").setExclusionStrategies(strategy).create().toJson(obj);
	}
	
	@SuppressWarnings("unchecked")
	public static String toJson(Object obj, Type type, JsonSerializer serializer){
		return new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").registerTypeAdapter(type, serializer).create().toJson(obj);
	}
}
